//
//  cooperateRecodeTableViewCell.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/24.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "cooperateRecodeTableViewCell.h"

#define CellHeight 140

#define Margin 8

#define TextFont 15

@interface cooperateRecodeTableViewCell ()

/**
 *  编号Label
 */
@property (nonatomic,strong)UILabel *numberLabel;

/**
 *  转入电话Label
 */
@property (nonatomic,strong)UILabel *phoneLabel;

/**
 *  转入金额Label
 */
@property (nonatomic,strong)UILabel *topUpMoney;

/**
 *  推广费Label
 */
@property (nonatomic,strong)UILabel *popularizeLabel;
@end

@implementation cooperateRecodeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addCooperateRecodeFirstCellUI];
        [self addCooperateRecodeSecondCellUI];
    }
    return self;
}

- (void)addCooperateRecodeFirstCellUI {
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = BACKGROUND_COLOR;
    [self.contentView addSubview:headerView];
    
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.contentView.mas_top);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(52);
    }];
    
    UIView *headerLineView = [[UIView alloc] init];
    headerLineView.backgroundColor = [UIColor blackColor];
    headerLineView.alpha = 0.1;
    [headerView addSubview:headerLineView];
    [self.contentView addSubview:headerLineView];
    
    [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(8);
        make.left.equalTo(self.contentView.mas_left);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(1);
    }];
    
    UILabel *headerLabel = [[UILabel alloc] init];
    headerLabel.text = @"交易成功";
    headerLabel.textColor = DEFAULT_COLOR;
    [headerView addSubview:headerLabel];
    [self.contentView addSubview:headerLabel];
    self.headerLabel = headerLabel;
    
    [headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin * 2);
        make.top.equalTo(headerLineView.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.3);
        make.height.mas_equalTo(44);
    }];
}

- (void)addCooperateRecodeSecondCellUI {
    UILabel *numberLabel = [[UILabel alloc] init];
    numberLabel.text = @"编号: 2918090";
    numberLabel.font = [UIFont systemFontOfSize:TextFont];
    numberLabel.textAlignment = NSTextAlignmentLeft;
    self.numberLabel = numberLabel;
    [self.contentView addSubview:numberLabel];
    
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin * 2);
        make.top.equalTo(self.headerLabel.mas_bottom);
        
//        if(iPhone5) {
            make.width.mas_equalTo(WIDTH * 0.4);
//        } else {
//            make.width.mas_equalTo(WIDTH * 0.3);
//        }
        
        make.height.mas_equalTo(44);
    }];

    UILabel *phoneLabel = [[UILabel alloc] init];
    phoneLabel.text = @"18620614920";
    phoneLabel.font = [UIFont systemFontOfSize:TextFont];
    phoneLabel.textAlignment = NSTextAlignmentRight;
    self.phoneLabel = phoneLabel;
    [self.contentView addSubview:phoneLabel];
    
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-Margin * 2);
        make.top.equalTo(self.headerLabel.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.4 + Margin * 2);
        make.height.mas_equalTo(44);
    }];
    
    UILabel *topUpMoney = [[UILabel alloc] init];
    topUpMoney.text = @"充值金额: ¥389008";
    topUpMoney.textAlignment = NSTextAlignmentLeft;
    topUpMoney.font = [UIFont systemFontOfSize:TextFont];
    self.topUpMoney = topUpMoney;
    [self.contentView addSubview:topUpMoney];
    
    [topUpMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin * 2);
        make.top.equalTo(numberLabel.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.5);
        make.height.mas_equalTo(44);
    }];
    
    UILabel *popularizeLabel = [[UILabel alloc] init];
    popularizeLabel.text = @"推广费: ¥8700";
    popularizeLabel.textAlignment = NSTextAlignmentRight;
    popularizeLabel.font = [UIFont systemFontOfSize:TextFont];
    self.popularizeLabel = popularizeLabel;
    [self.contentView addSubview:popularizeLabel];
    
    [popularizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-Margin * 2);
        make.top.equalTo(phoneLabel.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.4);
        make.height.mas_equalTo(44);
    }];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setCooperate:(cooperateModel *)cooperate {
    _cooperate = cooperate;
    
    
    
    self.numberLabel.text = [NSString stringWithFormat:@"编号: %@",cooperate.replaceID];
    self.phoneLabel.text = [NSString stringWithFormat:@"会员号: %@",cooperate.username];
    self.topUpMoney.text = [NSString stringWithFormat:@"充值金额: ¥%@",cooperate.jine];
    self.popularizeLabel.text = [NSString stringWithFormat:@"推广费: ¥%@",cooperate.tgf];
    
    
    if ([cooperate.zt isEqualToString:@"0"]) {
        self.headerLabel.text = @"正在交易中";
    } else if ([cooperate.zt isEqualToString:@"1"]) {
        self.headerLabel.text = @"交易成功";
    } else {
        self.headerLabel.text = @"交易失败";
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
